package com.originskyseed.platform.user.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.originskyseed.platform.core.tenant.util.TenantCodeUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Component;

import com.originskyseed.platform.core.base.BasePage;
import com.originskyseed.platform.core.util.bean.PrimaryKeyGeneratorUtil;
import com.originskyseed.platform.user.mapper.AnchorRelateLiveMapper;
import com.originskyseed.platform.user.mapper.AnchorRelateLiveStateMapper;
import com.originskyseed.platform.user.model.AnchorRelateLiveState;
import com.originskyseed.platform.user.service.IAnchorRelateLiveStateService;

/**
 * 主播直播状态信息表Service接口实现类（OSI_ANCHOR_RELATE_LIVE_STATE）
 * 
 * @author Tangwanghui
 */
@DubboService
@Component("anchorRelateLiveStateService")
public class AnchorRelateLiveStateServiceImpl implements IAnchorRelateLiveStateService {

	@Resource
	private AnchorRelateLiveStateMapper anchorRelateLiveStateMapper;

	@Resource
	private AnchorRelateLiveMapper anchorRelateLiveMapper;

	/**
	 * 删除记录
	 * 
	 * @param id
	 * @return
	 * @throws Exception
	 */
	@Override
	public int deleteByPrimaryKey(String id) throws Exception {
		return this.anchorRelateLiveStateMapper.deleteByPrimaryKey(id);
	}

	/**
	 * 批量删除记录
	 * 
	 * @param ids
	 * @return
	 * @throws Exception
	 */
	@Override
	public int deleteByPrimaryKeys(List<String> ids) throws Exception {
		return this.anchorRelateLiveStateMapper.deleteByPrimaryKeys(ids);
	}

	/**
	 * 插入记录
	 * 
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int insert(AnchorRelateLiveState record) throws Exception {
		if (StringUtils.isBlank(record.getId())) {
			record.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
		}
		record.setCreateTime(new Date());
		return this.anchorRelateLiveStateMapper.insert(record);
	}

	/**
	 * 插入记录（仅非空值字段）
	 * 
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int insertSelective(AnchorRelateLiveState record) throws Exception {
		if (StringUtils.isBlank(record.getId())) {
			record.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
		}
		record.setCreateTime(new Date());
		return this.anchorRelateLiveStateMapper.insertSelective(record);
	}

	/**
	 * 更新记录
	 * 
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int updateByPrimaryKey(AnchorRelateLiveState record) throws Exception {
		record.setUpdateTime(new Date());
		return this.anchorRelateLiveStateMapper.updateByPrimaryKey(record);
	}

	/**
	 * 更新记录（仅非空值字段）
	 * 
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int updateByPrimaryKeySelective(AnchorRelateLiveState record) throws Exception {
		record.setUpdateTime(new Date());
		return this.anchorRelateLiveStateMapper.updateByPrimaryKeySelective(record);
	}

	/**
	 * 查询记录
	 * 
	 * @param id
	 * @return
	 * @throws Exception
	 */
	@Override
	public AnchorRelateLiveState selectByPrimaryKey(String id) throws Exception {
		return this.anchorRelateLiveStateMapper.selectByPrimaryKey(id);
	}

	/**
	 * 查询列表
	 * 
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public List<AnchorRelateLiveState> selectList(AnchorRelateLiveState record) throws Exception {
		return this.anchorRelateLiveStateMapper.selectList(record);
	}

	/**
	 * 分页查询列表
	 * 
	 * @param params
	 * @param page
	 * @return
	 * @throws Exception
	 */
	@Override
	public BasePage<AnchorRelateLiveState> selectListByPage(Map<String, Object> params, BasePage<AnchorRelateLiveState> page) throws Exception {
		params.put("page", page);
		List<AnchorRelateLiveState> list = this.anchorRelateLiveStateMapper.selectListByPage(params);
		page.setResults(list);
		return page;
	}

	/**
	 * 批量插入记录
	 *
	 * @param list
	 * @return
	 * @throws Exception
	 */
	public int insertBatch(List<AnchorRelateLiveState> list) throws Exception {
		return this.anchorRelateLiveStateMapper.insertBatch(list);
	}


	/**
	 * 批量插入记录
	 *
	 * @param list
	 * @return
	 * @throws Exception
	 */
	public int insertBatch(String tenantCode,List<AnchorRelateLiveState> list) throws Exception
	{
		if(tenantCode!=null&&StringUtils.isNotBlank(tenantCode))
		{
			TenantCodeUtil.getInstance().createServerTenantCode(tenantCode);
		}
		return insertBatch(list);
	}

	/**
	 * 查询直播id和状态是否存在
	 * 
	 * @param list
	 * @return
	 * @throws Exception
	 */
	public List<AnchorRelateLiveState> selectLiveIds(String tenantCode,List<AnchorRelateLiveState> list) throws Exception {
		if(tenantCode!=null&&StringUtils.isNotBlank(tenantCode))
		{
			TenantCodeUtil.getInstance().createServerTenantCode(tenantCode);
		}
		return  selectLiveIds(list);
	}

	/**
	 * 查询直播id和状态是否存在
	 *
	 * @param list
	 * @return
	 * @throws Exception
	 */
	public List<AnchorRelateLiveState> selectLiveIds(List<AnchorRelateLiveState> list) throws Exception
	{
		return this.anchorRelateLiveStateMapper.selectLiveIds(list);
	}

}